
main_df <- main_df %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))


keep_bivariate_1 <-lm(group.dictator_payoff/1000 ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1, !(session.code %in% c("q30x01sj", "qtj4xm8s"))))
herf_bivariate_1 <- lm(herf_index_payout ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1,!(session.code %in% c("q30x01sj", "qtj4xm8s"))))
other_bivariate_1 <- lm(perc_other ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1,!(session.code %in% c("q30x01sj", "qtj4xm8s"))))

keep_bivariate_2 <-lm(group.dictator_payoff/1000 ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1,(session.code %in% c("q30x01sj", "qtj4xm8s"))))
herf_bivariate_2 <- lm(herf_index_payout ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1,(session.code %in% c("q30x01sj", "qtj4xm8s"))))
other_bivariate_2 <- lm(perc_other ~ factor(group.treatment), main_df %>% filter(pub_official_indicator == 1,(session.code %in% c("q30x01sj", "qtj4xm8s"))))

observations <- c(nobs(keep_bivariate_1),nobs(herf_bivariate_1),nobs(other_bivariate_1),
                  nobs(keep_bivariate_2),nobs(herf_bivariate_2),nobs(other_bivariate_2))

keep_bivariate_1 <- coeftest(keep_bivariate_1, vcov=vcovHC(keep_bivariate_1,type="HC0"))
herf_bivariate_1 <- coeftest(herf_bivariate_1, vcov=vcovHC(herf_bivariate_1,type="HC0"))
other_bivariate_1 <- coeftest(other_bivariate_1, vcov=vcovHC(other_bivariate_1,type="HC0"))
keep_bivariate_2 <- coeftest(keep_bivariate_2, vcov=vcovHC(keep_bivariate_2,type="HC0"))
herf_bivariate_2 <- coeftest(herf_bivariate_2, vcov=vcovHC(herf_bivariate_2,type="HC0"))
other_bivariate_2 <- coeftest(other_bivariate_2, vcov=vcovHC(other_bivariate_2,type="HC0"))

table <- list(keep_bivariate_1, herf_bivariate_1, other_bivariate_1, keep_bivariate_2, herf_bivariate_2, other_bivariate_2)

note_text <- paste("Beta coefficients from OLS regression. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes measures are the (1) absolute sum kept by the public officials; (2) a herfindahl index of participant shares; (3) the percent
                   of money given to other participants.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Pro-Sociality",
                  label = 'tab:pro_soc_session',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1 , 1, 1, 1, 1),
                  column.labels = c("Keep (IDR, k)", "Herf. Index (0-1)", "Share (\\%)", "Keep (IDR, k)", "Herf. Index (0-1)", "Share (\\%)"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Session", "1", "1", "1", "2", "2", "2"),
                                   c("Observations", observations)),
                  omit = c("player.age", "player.education"),
                  covariate.labels = c("Treatment: Merit", "Treatment: Patronage", "Intercept (Reference: Random)"),
                  
                  #star.cutoffs = c(0.05, 0.01),
                  #float.env = 'sidewaystable',
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 30)], note_text, './outputs/tables/table_a13.tex', .8)

